﻿#ifdef xxxx
#include <netinet/in.h>
#include <unistd.h>
//#include <sys/types.h>
#include "net/socket_op.h"

namespace SocketOp
{
    socket_t create(sa_family_t family)
    {
        socket_t socket_fd = ::socket(AF_INET, SOCK_STREAM | SOCK_NONBLOCK | SOCK_CLOEXEC, IPPROTO_TCP);
        return socket_fd;
    }
    
    void close(socket_t socket_fd)
    {
        if (::close(socket_fd) < 0)
        {
            // Error
        }
    }
    
    ssize_t read(socket_t socket_fd, void* buf, size_t buf_len)
    {
        return ::read(socket_fd, buf, buf_len);
    }
    
    ssize_t write(socket_t socket_fd, const void* buf, size_t buf_len)
    {
        return ::write(socket_fd, buf, buf_len);
    }

    int connect(socket_t socket_fd, const struct sockaddr_in &sa)
    {
        return ::connect(socket_fd, (struct sockaddr*)&sa, sizeof(sa));
    }

    int socketpair(socket_t fds[2], int domain/* = AF_UNIX*/, int type/* = SOCK_STREAM*/, int protocol/* = 0*/)
    {
        int result = ::socketpair(domain, type, protocol, fds);
        if (result == -1)
        {
            // Error
        }
        return result;
    }

} // namespace sockets

#endif // xxxx